import request from '@/utils/request'
import type { 
  ApiResponse,
  File
} from '@/types'

// 文件相关API
export const fileApi = {
  // 文件上传
  upload: (file: File): Promise<ApiResponse<File>> => {
    const formData = new FormData()
    formData.append('file', file)
    return request.post('/upload', formData)
  },

  // 图片上传
  uploadImage: (file: File): Promise<ApiResponse<File>> => {
    const formData = new FormData()
    formData.append('file', file)
    return request.post('/upload/image', formData)
  },

  // 获取文件列表
  getFileList: (): Promise<ApiResponse<File[]>> => {
    return request.get('/files')
  },

  // 获取文件信息
  getFileInfo: (fileId: number): Promise<ApiResponse<File>> => {
    return request.get(`/files/${fileId}`)
  },

  // 删除文件
  deleteFile: (fileId: number): Promise<ApiResponse<string>> => {
    return request.delete(`/files/${fileId}`)
  },

  // 文件下载
  downloadFile: (fileId: number): Promise<Blob> => {
    return request.get(`/download/${fileId}`, {
      responseType: 'blob'
    })
  }
}